// src/utils/response.ts
import { FastifyReply } from 'fastify';

export class ApiResponse<T> {
  static success<T>(
    reply: FastifyReply,
    data: T,
    msg: string = 'Success',
    code: number = 200
  ) {
    reply.code(code).send({
      code,
      msg,
      data // TS 自动推断 data 类型
    });
  }

  static error(
    reply: FastifyReply,
    msg: string = 'Error',
    code: number = 500
  ) {
    reply.code(code).send({
      code,
      msg,
      data: null // 明确返回 null 类型
    });
  }
}